#include "StdAfx.h"
#include "Groupe.h"


Groupe::Groupe(string nom):_nom(nom)
{
}
Groupe::~Groupe()
{
	for(list<ANote*>::const_iterator it = notes.begin(); it!=notes.end(); ++it)
    {
		delete *it;
	}
}


float Groupe::GetValeur() const
{
	double moyenne = 0;
	unsigned sumCoef=0;
	for(list<ANote*>::const_iterator it = notes.begin(); it!=notes.end(); ++it)
    {
		moyenne +=((ANote*)*it)->GetValeur() * ((ANote*)*it)->GetCoef();
		sumCoef += ((ANote*)*it)->GetCoef();
	}
	return (float)moyenne/sumCoef;
}

		
unsigned Groupe::GetCoef() const
{
	unsigned sumCoef=0;
	for(list<ANote*>::const_iterator it = notes.begin(); it!=notes.end(); ++it)
    {
		sumCoef += ((ANote*)*it)->GetCoef();
	}
	return sumCoef;
}

string Groupe::ToString() const {
	stringstream s ;
	s << "Groupe ["<< _nom <<"]"<< endl;

	for(list<ANote*>::const_iterator it = notes.begin(); it!=notes.end(); ++it)
    {
		s << ((ANote*)*it)->ToString() << endl;
	}

	s << "Moyenne : " << GetValeur() << "/20 (" << GetCoef() << ")"  << endl;

	return s.str();
}

ANote* Groupe::HeapClone() const{
	return new Groupe(*this);
}

void Groupe::AddNote(const ANote* note){
	
	notes.push_back(note->HeapClone());
}